//package com.nineshadow.games.redismq;
//
//import com.alibaba.fastjson.JSON;
//import com.nineshadow.games.constants.CommonConstants;
//import com.nineshadow.games.core.GameRoom;
//import com.nineshadow.games.interfaces.IGameUser;
//import com.nineshadow.games.launch.GameWorld;
//import com.nineshadow.games.launch.HallServer;
//import com.nineshadow.games.netty.message.MessageSend;
//import io.netty.channel.ChannelHandlerContext;
//import lombok.extern.slf4j.Slf4j;
//import net.sf.json.JSONObject;
//import org.springframework.data.redis.connection.Message;
//import org.springframework.data.redis.connection.MessageListener;
//
//import java.util.*;
//
//
///**
// * @author 描述：订阅监听类
// */
//@Slf4j
//public class SubscribeListener implements MessageListener {
//
////    /**
////     * 订阅接收发布者的消息
////     */
////    @Override
////    public void onMessage(Message message, byte[] pattern) {
////        String msg = new String(message.getBody());
////        JSONObject jsonObject = JSONObject.fromObject(msg);
////        if (null != session) {
////            try {
//////                log.info("{}，----收到消息：{}", session.channel(), msg);
////                boolean flag = true;
////                String method = jsonObject.getString("method");
////                Object sendMsg = null;
////                if (jsonObject.containsKey("msg")) {
////                    sendMsg = jsonObject.getString("msg");
////                    if (Objects.nonNull(sendMsg)) {
////                        JSONObject msgJson = JSONObject.fromObject(sendMsg);
////                        sendMsg = msgJson;
////                        flag = isFlag(method, msgJson);
////                    }
////                }
////                if (flag) {
////                    MessageSend.send(session, method, sendMsg, false);
////                }
////            } catch (Exception e) {
////                log.error(e.getMessage(), e);
////            }
////        }
////    }
////
////    private boolean isFlag(String method,Integer userId,JSONObject msgJson) {
////        Set<String> noSend = new HashSet<>();
////        noSend.add("again");
////        noSend.add("quitRoom");
////        noSend.add("gameScore");
////        noSend.add("openVoice");
////        noSend.add("emoji");
////        noSend.add("countDown");
////        boolean flag = true;
////        if (msgJson.containsKey("userId")) {
////            if (Objects.nonNull(userId)) {
////                if (msgJson.get("userId").equals(userId) && noSend.contains(method)) {
////                    flag = false;
////                }
////            }
////        }
////        if(method.equals("gameOver")){
////            GameRoom gameRoom=GameWorld.getRoom(msgJson.get("roomId").toString());
////            if(Objects.nonNull(gameRoom)){
////                gameRoom.terminate();
////            }
////        }
////        return flag;
////    }
////    @Override
////    public void onMessage(Message message, byte[] bytes) {
////		try {
////			String msg = new String(message.getBody());
////			JSONObject jsonObject = JSONObject.fromObject(msg);
//////			log.info("onMessage:{}",jsonObject);
////			String roomId = jsonObject.getString("roomId");
////            List<Integer> users=GameWorld.getRoomUsers(roomId);
////            for (Integer userId : users) {
////                IGameUser gameUser=GameWorld.getOnlineUser(userId);
////                if(Objects.isNull(gameUser)){
////                    continue;
////                }
////                boolean flag = true;
////                String method = jsonObject.getString("method");
////                Object sendMsg = null;
////                if (jsonObject.containsKey("msg")) {
////                    sendMsg = jsonObject.getString("msg");
////                    if (Objects.nonNull(sendMsg)) {
////                        JSONObject msgJson = JSONObject.fromObject(sendMsg);
////                        sendMsg = msgJson;
////                        flag = isFlag(method,gameUser.getUserId(), msgJson);
////                    }
////                }
////                if (flag) {
////                    gameUser.sendMsg(sendMsg,method);
////                }
////            }
////		}catch (Exception e){
////			log.error(e.getMessage(),e);
////		}
////
////    }
//}
